{include file='public/head'}
<body>
{load href="__CSS__/jquery.bigcolorpicker.css" /}
<style type="text/css" media="screen">
    header {
        color: black;
    }
</style>
<div class="x-body" >
    <form id="form" class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">后台名称</label>
            <div class="layui-input-block">
                <input type="text" name="admin_title" lay-verify="required" autocomplete="off" placeholder="请输入后台名称" class="layui-input" value="{$data.admin_title}">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button  class="layui-btn" lay-filter="add" lay-submit="">修改</button>
            </div>
        </div>

    </form>
</div>
</body>
{include file='public/foot'}
{load href="__JS__/jquery.bigcolorpicker.min.js" /}
<script type="text/javascript">
    $(function(){
        $("#img").bigColorpicker(function(el,color){
            $(el).css("background-color",color);
            $('#color').val(color);
        });
    });
</script>
<script type="text/javascript">
    layui.use(['form','layer','upload'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer,upload = layui.upload;

        //自定义验证规则
        form.verify({

        });

        var uploadInst1 = upload.render({
            elem: '#demo1'
            , url: '/admin/common/upFile'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code == 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                $('#adimg').val(res.data);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst1.upload();
                });
            }
        });

        //监听提交
        form.on('submit(add)', function(data){
            console.log(data);
            var form = new FormData();
            var t = $('#form').serializeArray();
            $.each(t, function() {
                form.append(this.name,this.value);
            });
            $.ajax({
                url:"{:url('admin/Index/config')}",
                type:"post",
                data:form,
                dataType: "json",
                processData:false,
                contentType:false,
                success:function(data){
                    if(data.code == 1){
                        layer.msg(data.msg,{icon:1,time:1000},function(){
                            location.reload();
                        });
                    }else{
                        layer.msg(data.msg,{icon: 2, time: 2000});
                    }
                }
            });
            return false;
        });

    });

</script>
